package com.kmxd.ams.app.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kmxd.ams.client.system.ISysDictSetSvc;
import com.kmxd.ams.core.common.query.QueryGen;
import com.kmxd.ams.core.util.IdUtil;
import com.kmxd.ams.infra.system.entity.SysDictSet;
import com.kmxd.ams.infra.system.mapper.SysDictSetMapper;
import java.util.List;
import java.util.Set;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 字典多版本表 服务实现类
 *
 * @author ZuoLG
 * @since 2022-10-09
 */
@Service
@AllArgsConstructor
public class SysDictSetSvcImpl extends ServiceImpl<SysDictSetMapper, SysDictSet>
    implements ISysDictSetSvc {

  private SysDictSetMapper sysDictSetMapper;

  @Override
  public Page<SysDictSet> selectPage(Page reqPage, SysDictSet req) {
    LambdaQueryWrapper<SysDictSet> queryWrapper =
        QueryGen.init(new QueryWrapper<SysDictSet>(), req).lambda();
    queryWrapper.orderByAsc(SysDictSet::getSort);
    return sysDictSetMapper.selectPage(reqPage, queryWrapper);
  }

  @Override
  public List<SysDictSet> selectList(SysDictSet req) {
    LambdaQueryWrapper<SysDictSet> queryWrapper =
        QueryGen.init(new QueryWrapper<SysDictSet>(), req).lambda();
    queryWrapper.orderByAsc(SysDictSet::getSort);
    return sysDictSetMapper.selectList(queryWrapper);
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void add(SysDictSet req) {
    sysDictSetMapper.insert(req);
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void edit(SysDictSet req) {
    sysDictSetMapper.updateById(req);
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void remove(String ids) {
    Set<Long> idList = IdUtil.split(ids);
    this.baseMapper.deleteBatchIds(idList);
  }

  @Override
  public SysDictSet view(Long id) {
    return sysDictSetMapper.selectById(id);
  }
}
